#!/bin/sh
PWD=`pwd`
PATCHER=$PWD/mod/patch.sh
PATCHES=`ls -1 mod/[0-9][0-9][0-9]-*.patch 2>/dev/null`
$PATCHER -Z $PWD/ $PATCHES
if [ $? -ne 0 ]; then
	echo "Can not apply patches" 1>&2
	exit 1
fi
MOD_REV=`cat $PWD/mod/.svnrev 2>/dev/null`
for a in httpd rc shared www
do
REV=`svnversion -c $PWD/$a 2>/dev/null | sed -e 's/.*://' -e 's/[A-Z]*$//'`
if [ $REV -gt $MOD_REV ]; then
	echo "Patch is outdated (module: $a, rev.: $MOD_REV, current: $REV)." 1>&2
	exit 1
fi
done
for a in $(cat $PWD/mod/dellist.txt); do
	rm -rf $PWD/$a
done
tar -C $PWD/mod/files -cf - . | tar -C $PWD -xvf -